package com.efesco.finance.oughtReceive;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;
import com.efesco.common.Tools;
import com.efesco.system.User;


/**
 * paymentGroupEmployeeViewModel
 */
public class paymentGroupEmployeeViewModel extends DefaultViewModel {
  	public void doCommit(ParameterSet parameters) throws Exception {
		Dataset paymentGroupdataset = getDataset("paymentGroupdataset");
		Dataset toEmployeeDataset = getDataset("toEmployeeDataset");
		String groupId = "";
		
		if (paymentGroupdataset.getCurrent() != null)  {
		    groupId = Tools.toStr(paymentGroupdataset.getString("PAYMENT_GROUP_ID"));
		    DBStatement statement = new DBStatement();
		    statement.setSql("delete from s_payment_group_employee ge where ge.payment_group_id="+groupId);
		    statement.execute();
		    statement.close();
		    
		    toEmployeeDataset.moveFirst();
		    while (!toEmployeeDataset.isLast())  {
		      statement.setSql("insert into s_payment_group_employee values(general.nextval,"
		            +groupId+","+toEmployeeDataset.getString("EMPLOYEE_ID")+")");
		      statement.execute();
		      statement.close();
		      toEmployeeDataset.moveNext();
		    }
		}

	}

}
